package com.njwb.day15.zqzb.ios.io3;

import java.io.*;

public class dBufferedWriterDemo01 {
    public static void main(String[] args) {

        BufferedWriter bufferedWriter = null ;
        Writer writer = null;
        try {
            //实例化的时候，先实例化节点流，然后在实例化过滤流
            writer = new FileWriter(new File("chapter02/src/bw.txt"));
            bufferedWriter = new BufferedWriter(writer);


            bufferedWriter.write("湖人总冠军，口号都喊了快7年了",0,5);
            //创建了新的一行
            bufferedWriter.newLine();
            bufferedWriter.write("苏超总决赛即将开始。。");
            bufferedWriter.newLine();
            bufferedWriter.write("helloworld");

            bufferedWriter.flush();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            //关闭的时候倒着关闭
            if(bufferedWriter!=null) {
                try {
                    bufferedWriter.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(writer!=null) {
                try {
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }






    }
}
